﻿<phone:PhoneApplicationPage x:Class="Wulong.Phone.Qiushi.Views.QiushiListView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" 
    xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    d:DesignHeight="800" d:DesignWidth="480"
    Style="{StaticResource TransitionPageStyle}">

    <phone:PhoneApplicationPage.Resources>

        <Style x:Key="ListBoxStyle1" TargetType="ListBox">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="BorderThickness" Value="0"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">

                        <ScrollViewer x:Name="ScrollViewer" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" Padding="{TemplateBinding Padding}">
                            <StackPanel>
                                <ItemsPresenter/>
                                <Button Content="{Binding Path=AppI18N.V_QiushiList_Button_LoadMore, Source={StaticResource ls}}" BorderBrush="Transparent" BorderThickness="0" Visibility="{Binding CanLoadMore, 
                        Converter={StaticResource BooleanToVisibilityConverter}}" Margin="0,0,0,50">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="Click">
                                            <cal:ActionMessage MethodName="LoadMore" />
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Button>
                            </StackPanel>
                        </ScrollViewer>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </phone:PhoneApplicationPage.Resources>
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <adduplex:AdControl xmlns:adduplex="clr-namespace:AdDuplex;assembly=AdDuplex.AdControl.Silverlight"
                            Grid.Row="0" 
                            AppId="3423" 
                            Background="Transparent"
                            BackgroundOpacity="0.5"
                            />
        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="1" Margin="12,17,0,28" Orientation="Vertical">
            <TextBlock x:Name="ApplicationTitle" Text="{Binding Path=AppI18N.App_Title, Source={StaticResource ls}}" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="{Binding DisplayName}" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}"/>
        </StackPanel>
        <!--Listbox's performance is not good, hopefully will get fixed in mango-->
        <ListBox x:Name="QiushiItems" Style="{StaticResource ListBoxStyle1}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" Grid.Row="2">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <toolkit:ContextMenuService.ContextMenu>
                            <toolkit:ContextMenu IsZoomEnabled="false" cal:Action.TargetWithoutContext="{Binding DataContext, ElementName=QiushiItems}">
                                <toolkit:MenuItem x:Name="LaunchPictureViewer" Header="{Binding Path=AppI18N.V_QiushiList_LaunchPictureViewer_ContextMenu, Source={StaticResource ls}}" cal:Message.Attach="[Event Click]=[Action LaunchPictureViewer($dataContext)]"/>
                                <toolkit:MenuItem x:Name="SentByEmailCommand" Header="{Binding Path=AppI18N.V_QiushiList_SentByEmail_ContextMenu, Source={StaticResource ls}}" cal:Message.Attach="[Event Click]=[Action SentByEmailCommand($dataContext)]"/>
                                <toolkit:MenuItem Header="{Binding Path=AppI18N.V_QiushiList_SentBySMS_ContextMenu, Source={StaticResource ls}}" cal:Message.Attach="[Event Click]=[Action SentBySmsCommand($dataContext)]"/>
                                <toolkit:MenuItem Header="{Binding Path=AppI18N.V_QiushiList_ViewComments_ContextMenu, Source={StaticResource ls}}" cal:Message.Attach="[Event Click]=[Action NavigateToCommentsView($dataContext)]"/>
                            </toolkit:ContextMenu>
                        </toolkit:ContextMenuService.ContextMenu>
                        <TextBlock Text="{Binding Content}" TextWrapping="Wrap" Style="{StaticResource PhoneTextNormalStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" />
                        <Button x:Name="ViewPicture" Background="Transparent" BorderThickness="0" Padding="0" cal:Message.Attach="[Event Click]=[Action ViewPicture($this)]">
                            <Image>
                                <Image.Source>
                                     <BitmapImage UriSource="{Binding ImageUrl}" CreateOptions="BackgroundCreation"/>                   	
                                </Image.Source>
                            </Image>
                        </Button>
                        
                            <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" >
                                <TextBlock 
                            Text="{Binding Path=AppI18N.V_QiushiList_Tags, Source={StaticResource ls}}" 
                            Style="{StaticResource PhoneTextSmallStyle}" />
                                
                                    <TextBlock 
                            Text="{Binding Tags}" 
                            Style="{StaticResource PhoneTextAccentStyle}"
                            TextWrapping="Wrap"/>
                                
                            </StackPanel>
                        
                        
                        <Border Background="{StaticResource PhoneChromeBrush}">
                            
                            <!--bar-->
                            <Button x:Name="ViewComments" 
                                    Background="Transparent" 
                                    BorderThickness="0" 
                                    Padding="0"
                                    VerticalAlignment="Top"
                                    cal:Message.Attach="[Event Click]=[Action ViewComments($this)]">
                                <StackPanel x:Name="commentsBar" HorizontalAlignment="Left" Orientation="Horizontal" >
                                    <Image Height="20" Source="/Images/thumbs_up.png" VerticalAlignment="Center" Margin="12,0,0,0"/>
                                    <TextBlock 
                                    Margin="0"
                                    Text="{Binding Tops}" 
                                    VerticalAlignment="Center" 
                                    Style="{StaticResource PhoneTextSmallStyle}" />
                                    <TextBlock 
                                    Margin="0"
                                    VerticalAlignment="Center" 
                                    Text="{Binding Path=AppI18N.V_QiushiList_People_Like, Source={StaticResource ls}}" 
                                    Style="{StaticResource PhoneTextSmallStyle}" />
                                    <Image VerticalAlignment="Center" Height="20" Source="/Images/thumbs_down.png" Margin="12,0,0,0"/>
                                    <TextBlock 
                                    Margin="0"
                                     VerticalAlignment="Center" 
                                     Text="{Binding Flops}" 
                                     Style="{StaticResource PhoneTextSmallStyle}"/>
                                    <TextBlock 
                                    Margin="0"
                                    VerticalAlignment="Center" 
                                    Text="{Binding Path=AppI18N.V_QiushiList_People_Dislike, Source={StaticResource ls}}" 
                                    Style="{StaticResource PhoneTextSmallStyle}" />
                                    <Image VerticalAlignment="Center" Height="20" Source="/Images/comments.png" Margin="12,0,0,0"/>
                                    <TextBlock 
                                    Margin="0"
                                    VerticalAlignment="Center" 
                                    Text="{Binding CommentsCount}" 
                                    Style="{StaticResource PhoneTextSmallStyle}"/>
                                    <TextBlock
                                    Margin="0" 
                                    VerticalAlignment="Center" 
                                    Text="{Binding Path=AppI18N.V_QiushiList_PeopleComment, Source={StaticResource ls}}" 
                                    Style="{StaticResource PhoneTextSmallStyle}" />
                                </StackPanel>
                            </Button>
                        </Border>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        
        <!--Loading bar and text-->
        <Grid Grid.Row="0"
                      Visibility="{Binding IsBusy, 
                            Converter={StaticResource BooleanToVisibilityConverter}}">
            <TextBlock Grid.Row="2" Text="{Binding Path=AppI18N.App_Loading, Source={StaticResource ls}}" 
                               Style="{StaticResource LoadingStyle}"/>
            <toolkit:PerformanceProgressBar IsIndeterminate="{Binding IsBusy}"
                                 VerticalAlignment="Top" 
                                 IsTabStop="True"
                                 Grid.Row="2" />
        </Grid>
    </Grid>
</phone:PhoneApplicationPage>